package com.ys.controller.api.storage;

import com.ys.config.MenuId;
import com.ys.entity.storage.TccFbaLogisticsMethod;
import com.ys.entity.storage.TccFbaPlan;
import com.ys.service.storage.TccFbaLogisticsMethodService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: xjx
 * @CreateTime: 2024-12-05
 * @Description: 预估物流方式详情
 * @Version: 1.5
 */
@Controller
@RequestMapping("/api/inter/tccFbaLogisticsMethod")
public class ApiInterTccFbaLogisticsMethodController {
    private static final Logger logger = LoggerFactory.getLogger(ApiInterTccFbaLogisticsMethodController.class);

    @Autowired
    private TccFbaLogisticsMethodService tccFbaLogisticsMethodService;

    @Autowired
    private CommonApiService<TccFbaLogisticsMethod> commonApiService;

    //菜单id
    private Long menuId = MenuId.TCC_FbaLogisticsMethodJh;


    @RequestMapping("/searchsearchEstimated")
    @ResponseBody
    public LayuiTableVoJA searchEstimated(@ModelAttribute TccFbaLogisticsMethod cond, String conditions){
        cond = setSeachSql(cond)

                .where("A.SourceType=0");

        LayuiTableVoJA vo = commonApiService.searchLay(cond);
        return vo;
    }


    @RequestMapping("/searchActual")
    @ResponseBody
    public LayuiTableVoJA searchActual1(@ModelAttribute TccFbaLogisticsMethod cond, String conditions){
        cond = setSeachSql1(cond)

                .where("A.SourceType=1");

        LayuiTableVoJA vo = commonApiService.searchLay(cond);
        return vo;
    }


    /**
     * 设置查询的cond的sql设置
     * @param cond
     * @return
     */
    public TccFbaLogisticsMethod setSeachSql(TccFbaLogisticsMethod cond){

        cond.addLeftJoin("TCC_FbaPlan tfp ON tfp.Bid=A.SourceBid")
                .addLeftJoin("YS_ProcInst P ON P.Bid = tfp.Bid ")
                .addField("tfp.Bid bid,tfp.CreationMethod creationMethod,tfp.DeliverState deliverState,tfp.Vgsbm vgsbm,tfp.VgsJc vgsJc,tfp.ShopName shopName,tfp.AuditingTime auditingTime,tfp.AuditingUser auditingUser,tfp.Vgsbm vgsBm,tfp.VgsJc vgsjc")
                .addField("FORMAT(A.createTime, 'yyyy-MM-dd HH:mm:ss') createTime1");//生效时间
        cond = commonApiService.dataAuth(menuId, cond);
        return  cond;
    }

    /**
     * 设置查询的cond的sql设置
     * @param cond
     * @return
     */
    public TccFbaLogisticsMethod setSeachSql1(TccFbaLogisticsMethod cond){

        cond.addLeftJoin("TCC_FbaDeliver tfd ON tfd.Bid=A.SourceBid AND A.SourceType = 1")
                .addLeftJoin("TCC_FbaPlan tfp ON tfp.Bid=tfd.FbaPlanBid")
                .addLeftJoin("YS_ProcInst P ON P.Bid = tfp.Bid ")
                .addField("tfp.Bid planBid,tfd.Bid sourceBid,tfp.CreationMethod creationMethod,tfp.DeliverState deliverState,tfp.Vgsbm vgsbm,tfp.VgsJc vgsJc,tfp.ShopName shopName,tfp.AuditingTime auditingTime,tfp.AuditingUser auditingUser,tfp.Vgsbm vgsBm,tfp.VgsJc vgsjc")
                .addField("FORMAT(A.createTime, 'yyyy-MM-dd HH:mm:ss') createTime1");//生效时间
        cond = commonApiService.dataAuth(menuId, cond);
        return  cond;
    }



}
